// GA_BPA.cpp: implementation of the CGA_BPA class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "../../Include/Swi/GA_BPA.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CGA_BPA::CGA_BPA()
{
	m_chType = 'G';
	m_chSubType = 'A';
	m_chChangeCode = ' ';

	m_dPe = 0;
	m_dTc = 0;
	m_dTo = 0;
	m_dVELclose = 0;
	m_dVELopen = 0;
	m_dPmax = 0;
	m_dPmin = 0;
	m_dT1 = 0;
	m_dKp = 0;
	m_dKd = 0;
	m_dKi = 0;
	m_dINTGmax = 0;
	m_dINTGmin = 0;
	m_dPIDmax = 0;
	m_dPIDmin = 0;

	m_strCardType[0] = 'G';

}

CGA_BPA::CGA_BPA(CGA_BPA &gaBPA):CUnit_BPA(gaBPA)
{
	m_dPe = gaBPA.m_dPe;
	m_dTc = gaBPA.m_dTc;
	m_dTo = gaBPA.m_dTo;
	m_dVELclose = gaBPA.m_dVELclose;
	m_dVELopen = gaBPA.m_dVELopen;
	m_dPmax = gaBPA.m_dPmax;
	m_dPmin = gaBPA.m_dPmin;
	m_dT1 = gaBPA.m_dT1;
	m_dKp = gaBPA.m_dKp;
	m_dKd = gaBPA.m_dKd;
	m_dKi = gaBPA.m_dKi;
	m_dINTGmax = gaBPA.m_dINTGmax;
	m_dINTGmin = gaBPA.m_dINTGmin;
	m_dPIDmax = gaBPA.m_dPIDmax;
	m_dPIDmin = gaBPA.m_dPIDmin;
}

CGA_BPA::~CGA_BPA()
{

}

bool CGA_BPA::FillEx(char *buffer)
{
	bool bResult = CUnit_BPA::FillEx(buffer);

	if (!bResult)
	{
		printf("Error in (CGA_BPA::FillEx): no basic information!\n");
		return false;
	}

	if (strlen(buffer)<17)
		return true;

	m_dPe = StrToDouble(&buffer[16],6,2);
	if(EndOfSec(&buffer[16],6))
		return true;

	m_dTc = StrToDouble(&buffer[22],4,2);
	if(EndOfSec(&buffer[22],4))
		return true;

	m_dTo = StrToDouble(&buffer[26],4,2);
	if(EndOfSec(&buffer[26],4))
		return true;

	m_dVELclose = StrToDouble(&buffer[30],4,2);
	if(EndOfSec(&buffer[30],4))
		return true;

	m_dVELopen = StrToDouble(&buffer[34],4,2);
	if(EndOfSec(&buffer[34],4))
		return true;

	m_dPmax = StrToDouble(&buffer[38],4,2);
	if(EndOfSec(&buffer[38],4))
		return true;

	m_dPmin = StrToDouble(&buffer[42],4,2);
	if(EndOfSec(&buffer[42],4))
		return true;

	m_dT1 = StrToDouble(&buffer[46],4,2);
	if(EndOfSec(&buffer[46],4))
		return true;

	m_dKp = StrToDouble(&buffer[50],4,2);
	if(EndOfSec(&buffer[50],4))
		return true;

	m_dKd = StrToDouble(&buffer[54],4,2);
	if(EndOfSec(&buffer[54],4))
		return true;

	m_dKi = StrToDouble(&buffer[58],4,2);
	if(EndOfSec(&buffer[58],4))
		return true;

	m_dINTGmax = StrToDouble(&buffer[62],4,2);
	if(EndOfSec(&buffer[62],4))
		return true;

	m_dINTGmin = StrToDouble(&buffer[66],4,2);
	if(EndOfSec(&buffer[66],4))
		return true;

	m_dPIDmax = StrToDouble(&buffer[70],4,2);
	if(EndOfSec(&buffer[70],4))
		return true;

	m_dPIDmin = StrToDouble(&buffer[74],4,2);
	if(EndOfSec(&buffer[74],4))
		return true;

	return true;
}

bool CGA_BPA::UpdateEx(char *buffer)
{
	bool bResult = CUnit_BPA::UpdateEx(buffer);

	if (!bResult)
	{
		printf("Error in (CGA_BPA::UpdateEx): impossible!\n");
		return false;
	}

	DoubleToStr(m_dPe,&buffer[16],6,2);
	DoubleToStr(m_dTc,&buffer[22],4,2);
	DoubleToStr(m_dTo,&buffer[26],4,2);
	DoubleToStr(m_dVELclose,&buffer[30],4,2);
	DoubleToStr(m_dVELopen,&buffer[34],4,2);
	DoubleToStr(m_dPmax,&buffer[38],4,2);
	DoubleToStr(m_dPmin,&buffer[42],4,2);
	DoubleToStr(m_dT1,&buffer[46],4,2);
	DoubleToStr(m_dKp,&buffer[50],4,2);
	DoubleToStr(m_dKd,&buffer[54],4,2);
	DoubleToStr(m_dKi,&buffer[58],4,2);
	DoubleToStr(m_dINTGmax,&buffer[62],4,2);
	DoubleToStr(m_dINTGmin,&buffer[66],4,2);
	DoubleToStr(m_dPIDmax,&buffer[70],4,2);
	DoubleToStr(m_dPIDmin,&buffer[74],4,2);

	return true;
}
